﻿Imports System.Windows.Forms

Public Class frmNumberFormat

    Private mCurrentCount As Double = 10000.005

    Private mValue As String
    Public Property Value() As String
        Get
            Return mValue
        End Get
        Set(ByVal value As String)
            mValue = value
        End Set
    End Property


    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        mValue = txt.Text
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub frmDateFormat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'mValue = ""
        Dim dt As DataTable = GetDataTable()
        Dim dr As DataRow = dt.NewRow

        dr("format") = ""
        dr("output") = CStr(1234.5678).ToString()
        dr("current") = 1234.5678
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "C"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "C1"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "C2"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "C3"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "D"
        dr("output") = CLng(mCurrentCount).ToString(dr("format"))
        dt.Rows.Add(dr)


        dr = dt.NewRow
        dr("format") = "E"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "E1"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "E2"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "E3"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)


        dr = dt.NewRow
        dr("format") = "F"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)



        dr = dt.NewRow
        dr("format") = "F1"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)


        dr = dt.NewRow
        dr("format") = "F2"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "F3"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "F4"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "G"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "G1"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "G2"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "G3"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "G4"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)


        dr = dt.NewRow
        dr("format") = "N"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)
        dr = dt.NewRow
        dr("format") = "N1"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)


        dr = dt.NewRow
        dr("format") = "N2"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "N3"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)
        dr = dt.NewRow
        dr("format") = "N4"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "P"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "P1"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "P2"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "P3"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "P4"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "R"
        dr("output") = mCurrentCount.ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "X"
        dr("output") = CLng(mCurrentCount).ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "X1"
        dr("output") = CLng(mCurrentCount).ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "X2"
        dr("output") = CLng(mCurrentCount).ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "X3"
        dr("output") = CLng(mCurrentCount).ToString(dr("format"))
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("format") = "X4"
        dr("output") = CLng(mCurrentCount).ToString(dr("format"))
        dt.Rows.Add(dr)

        grd.DataSource = dt

        Timer1_Tick(Nothing, Nothing)

        If Len(mValue) > 0 Then
            For RowIndex As Long = 0 To grd.Rows.Count - 1
                If grd.Rows(RowIndex).Cells(0).Value = mValue Then
                    grd.Rows(RowIndex).Selected = True
                    grd.CurrentCell = grd.Rows(RowIndex).Cells(0)


                    txt.Text = grd.Rows(RowIndex).Cells(0).Value
                End If
            Next
        End If

    End Sub

    Private Function GetDataTable() As DataTable
        Dim dt As New DataTable
        Dim DataColumn As New DataColumn
        DataColumn.ColumnName = "Format"
        DataColumn.DataType = GetType(String)
        dt.Columns.Add(DataColumn)

        DataColumn = New DataColumn
        DataColumn.ColumnName = "Output"
        DataColumn.DataType = GetType(String)
        dt.Columns.Add(DataColumn)


        DataColumn = New DataColumn
        DataColumn.ColumnName = "Current"
        DataColumn.DataType = GetType(String)
        dt.Columns.Add(DataColumn)

        Return dt
    End Function

    Private Sub grd_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grd.CellClick
        txt.Text = grd.Rows(e.RowIndex).Cells(0).Value
    End Sub

    Private Sub grd_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grd.CellContentClick

    End Sub

    Private Sub txt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt.TextChanged
        lblExampleTime.Text = mCurrentCount
        ' lblExample.Text = Now.ToString(txt.Text)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        mCurrentCount = mCurrentCount + 1
        txt_TextChanged(Nothing, Nothing)

        For i As Long = 0 To grd.Rows.Count - 1
            'grd.Rows(i).Cells(2).Value = Now.ToString(grd.Rows(i).Cells(0).Value)
        Next

    End Sub
End Class
